package com.liuyang.concurrency.chapter7;

import java.util.concurrent.locks.Lock;

public class SynchronizedThis {
    public static void main(String[] args) {
        ThisLock lock = new ThisLock();
        new Thread("T1") {
            @Override
            public void run() {
                lock.m1();
            }
        }.start();

        new Thread("T2") {
            @Override
            public void run() {
                lock.m2();
            }
        }.start();


    }

}

class ThisLock {

    private final Object LOCK = new Object();
    private final Object LOCK1 = new Object();

    public void m1() {
        synchronized (LOCK) {
            try {
                System.out.println(Thread.currentThread().getName() + " 进来了m1");
                Thread.sleep(10_000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    public void m2() {
        synchronized (LOCK1) {
            try {
                System.out.println(Thread.currentThread().getName() + " 进来了m2");
                Thread.sleep(10_000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}